import { defineStore } from 'pinia'
import { getPowerViewData } from '@/services/modules/power-view'
import type {
  TProcessMonitoringData,
  TChargingPileOption,
  TchargingStatisticsData,
} from '@/components/page-echarts/types/option'

interface IPowerView {
  chargingPile: any[]
  processMonitoring: TProcessMonitoringData
  chargingStatistics: TchargingStatisticsData
  exceptionMonitoring: any[]
  dataAnalysis: any[]

  chargingTop4: TChargingPileOption
  percentage: number
}

export const usePowerViewStore = defineStore('powerView', {
  state: (): IPowerView => ({
    chargingPile: [],
    processMonitoring: [
      {
        name: '设备1',
        data: [],
      },
      {
        name: '设备1',
        data: [],
      },
    ],
    chargingStatistics: [],
    exceptionMonitoring: [],
    dataAnalysis: [],

    chargingTop4: [],
    percentage: 0,
  }),
  actions: {
    async powerViewDataAction() {
      const res = await getPowerViewData()

      this.chargingPile = res.data.chargingPile.data
      this.processMonitoring = res.data.processMonitoring.data

      this.chargingStatistics = res.data.chargingStatistics.data
      this.exceptionMonitoring = res.data.exceptionMonitoring.data
      this.dataAnalysis = res.data.dataAnalysis.data

      this.chargingTop4 = res.data.chargingTop4.data
      this.percentage = res.data.chargingTop4.totalPercentage

      console.log(this.chargingPile, this.processMonitoring)
    },
  },
})
